package com.kuaidao.common.util;

import com.kuaidao.common.constant.SysErrorCodeEnum;
import com.kuaidao.common.entity.JSONResult;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

import java.util.List;

public class CommonUtil {

    public static JSONResult validateParam(BindingResult result){
        List<ObjectError> allErrors = result.getAllErrors();
        for (ObjectError allError : allErrors) {
            return new JSONResult<>().fail(SysErrorCodeEnum.ERR_ILLEGAL_PARAM.getCode(),allError.getDefaultMessage());
        }
        return new JSONResult().fail(SysErrorCodeEnum.ERR_ILLEGAL_PARAM.getCode(),SysErrorCodeEnum.ERR_ILLEGAL_PARAM.getMessage());

    }
}
